module.exports = {
  formatTime: date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  },
  formatNumber: n => {
    n = n.toString()
    return n[1] ? n : '0' + n
  },
  checkStr: (str,type) => {
    switch(type) {
      case 'phone':
        return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
      case 'card':
        return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
      default:
        return null
    }
  }
}


